package com.timemanager.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.timemanager.R;
import com.timemanager.model.Event;

import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button startEvent;
    private Button todayEvents;
    private Button addEventTime;
    private Button addEvent;
    private Button editEvent;
    private Button historyEvents;
    private Button setPassword;
    private Button about;
    private Button exit;
    private String today;
    private TextView titleText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        startEvent = (Button) findViewById(R.id.start_event);
        todayEvents = (Button) findViewById(R.id.today_events);
        addEventTime = (Button) findViewById(R.id.add_event_time);
        addEvent = (Button) findViewById(R.id.add_event);
        editEvent = (Button) findViewById(R.id.edit_event);
        historyEvents = (Button) findViewById(R.id.history_events);
        setPassword = (Button) findViewById(R.id.set_password);
        about = (Button) findViewById(R.id.about);
        exit = (Button) findViewById(R.id.exit);
        titleText = (TextView)findViewById(R.id.title_text);
        titleText.setText("时间管理助手");
        startEvent.setOnClickListener(this);
        todayEvents.setOnClickListener(this);
        addEventTime.setOnClickListener(this);
        addEvent.setOnClickListener(this);
        editEvent.setOnClickListener(this);
        historyEvents.setOnClickListener(this);
        setPassword.setOnClickListener(this);
        about.setOnClickListener(this);
        exit.setOnClickListener(this);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        today = format.format(new Date());
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.start_event:
                Intent intent1 = new Intent(MainActivity.this, EventSelectorActivity.class);
                intent1.putExtra("come_from", "start_event");
                startActivity(intent1);
                break;
            case R.id.today_events:
                Intent intent2 = new Intent(MainActivity.this, HistoryEventTimeActivity.class);
                intent2.putExtra("from_date", today);
                intent2.putExtra("to_date", today);
                startActivity(intent2);
                break;
            case R.id.add_event_time:
                Intent intent3 = new Intent(MainActivity.this, EventSelectorActivity.class);
                intent3.putExtra("come_from", "add_event_time");
                startActivity(intent3);
                break;
            case R.id.add_event:
                Intent intent4 = new Intent(MainActivity.this, EventSelectorActivity.class);
                intent4.putExtra("come_from", "add_event");
                startActivity(intent4);
                break;
            case R.id.edit_event:
                Intent intent5 = new Intent(MainActivity.this, EventSelectorActivity.class);
                intent5.putExtra("come_from", "edit_event");
                startActivity(intent5);
                break;
            case R.id.history_events:
                Intent intent6 = new Intent(MainActivity.this, DatePickerActivity.class);
                startActivity(intent6);
                break;
            case R.id.set_password:
                Intent intent7 = new Intent(MainActivity.this, SetPassword.class);
                startActivity(intent7);
                break;
            case R.id.about:
                Intent intent8 = new Intent(MainActivity.this, AboutActivity.class);
                startActivity(intent8);
                break;
            case R.id.exit:
                finish();
                break;
            default:
                break;
        }
    }
}
